package mul.UI;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.swarmconnect.Swarm;
import com.swarmconnect.SwarmActivity;
import com.swarmconnect.SwarmLeaderboardScore;
import com.swarmconnect.SwarmUser;

import mul.Storage.*;

public class HighScoreActivity extends SwarmActivity{
	
	
	
	private final String COLUMN1_TAG = "name";
	private final String COLUMN2_TAG = "score";
	private SimpleAdapter myAdapter;
	private ArrayList<HashMap<String, String>> myAdapterlist;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.highscore_activity);
		LeaderBoardInterface.addListener(this);
		LeaderBoardInterface.updateHighScoreActivityList(this);
		

		}
		

	public void updateGUI(SwarmLeaderboardScore[] scores) {
		
		if(scores == null){
			
			//SHOW EMPTY LSIT
			
		}else{
		
		myAdapterlist = new ArrayList<HashMap<String, String>>();
		myAdapter = new SimpleAdapter(this, myAdapterlist, R.layout.highscore_row,  
				new String []{COLUMN1_TAG, COLUMN2_TAG}, new int[] {R.id.hiscoreElement_NAME, R.id.highscoreElement_SCORE});
		
		ListView myListView = (ListView) findViewById(R.id.highscoreView);
		myListView.setAdapter(myAdapter);
		
		HashMap row;
		
			for(int i=0; i<scores.length; i++){
				row = new HashMap(); 
				row.put(COLUMN1_TAG, scores[i].user.username);
				row.put(COLUMN2_TAG, Float.toString(scores[i].score));
				myAdapterlist.add(row);
			}
		}
	}
}

	






